home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 19 / CD_ASCQ_19_010295.iso / dos / prg / pas / swag / mouse.swg / 0023_Anivga Sprite Mouse V0.4.pas < prev    next >
Pascal/Delphi Source File  |  1994-08-24  |  5KB  |  141 lines

  1. (* ************************************************************************
  2.    Example of ANIVGA sprite mouse using the default TurboVision Drivers unit.
  3.    Procedures in Drivers unit divide MouseInt coordinates (i.e. SAR 3) by 8 to
  4.    convert into TPoint screen coordinates.  TPoint is an object containing a
  5.    pair of Integers.  Consequently, the default mouse is pixel precise for X =
  6.    0..79 and Y = 0..24 but should be scaled back up for a larger range.
  7.  
  8.    Changing the source code from the Drivers unit is best approach.  Make a
  9.    clone unit that has the same keyboard/mouse constants and routines for the
  10.    event-loop.  And ignore the rest.  Otherwise multiply TEvent.Where values
  11.    by 8 repeatedly.  As shown, precision is reduced to 8 pixels as a result.
  12.    ************************************************************************ *)
  13. {$A+,B-,D+,L+,N-,E-,O-,R-,S-,V-,G-,F-,I-,X-}
  14. {$M 16384,0,655360}
  15. PROGRAM SpriteMouse;
  16. { Author: John Howard  jh
  17.   Version 0.4
  18.   Date: July 23, 1994
  19. }
  20. USES {original sinusoid code from Kai Rohrbacher}
  21.      ANIVGA
  22.     ,Drivers;            {TurboVision event-driven mouse & keyboard}
  23.  
  24. CONST LoadNumber=42;
  25.       TileName='AEGYPTEN.COD';  {Path & name of any sprite tile to load}
  26.       FirstTile=0;
  27.       Tiles_per_Row=2;          {TileWidth}
  28.       Tiles_per_Column=2;       {TileHeight}
  29.       SpriteName='FLOWER.COD';  {Path & name of any sprite to load}
  30.       CartoonName='HANTEL.LIB'; {Path & name of animated mouse cursor library}
  31.       CartoonHandle=1;
  32.       Cartoon=1;                {sprite number}
  33.       MouseHandle=LoadNumber;   {Clone mouse cursor}
  34.       Mouse=0;                  {sprite number}
  35.       Surf=Mouse +15;           {just a sprite number above split index}
  36.       OFF=0;                    {Switch sprite OFF}
  37. VAR
  38.     x : INTEGER;
  39.     Event : TEvent;      {Drivers}
  40.     MaxFrame : word;
  41.     FrameCount : word;
  42.  
  43. CONST
  44. { CRT Foreground and background color constants }
  45.   Black         = 0;
  46.   Blue          = 1;
  47.   Green         = 2;
  48.   Cyan          = 3;
  49.   Red           = 4;
  50.   Magenta       = 5;
  51.   Brown         = 6;
  52.   LightGray     = 7;
  53.  
  54. { CRT Foreground color constants }
  55.   DarkGray      = 8;
  56.   LightBlue     = 9;
  57.   LightGreen    = 10;
  58.   LightCyan     = 11;
  59.   LightRed      = 12;
  60.   LightMagenta  = 13;
  61.   Yellow        = 14;
  62.   White         = 15;
  63.  
  64. BEGIN
  65.  IF loadSprite(SpriteName,LoadNumber)=0
  66.   THEN BEGIN
  67.         WRITELN('Couldn''t access file '+SpriteName+' : '+GetErrorMessage);
  68.         halt(1)
  69.        END;
  70.  MaxFrame:=loadSprite(CartoonName,CartoonHandle);
  71. {$IFDEF DEBUG}
  72.     writeln(CartoonName+' contains : ', MaxFrame); halt(1);
  73. {$ENDIF}
  74.  IF Error<>Err_None
  75.   THEN BEGIN
  76.         WRITELN('Couldn''t access file '+CartoonName+' : '+GetErrorMessage);
  77.         halt(1)
  78.        END;
  79.  InitEvents;             {Drivers}
  80.  HideMouse;              {Drivers}
  81.  
  82.  InitGraph;
  83.  IF loadTile(TileName, FirstTile)=0
  84.   THEN BEGIN
  85.         CloseRoutines;
  86.         DoneEvents;      {Drivers}
  87.         WRITELN('Couldn''t access file '+TileName+' : '+GetErrorMessage);
  88.         halt(1)
  89.        END;
  90.  FillBackground(LightRed);               {Border}
  91.  SetAnimateWindow(32,24, XMAX-32, YMAX-24);
  92.  SetBackgroundMode(SCROLLING);           {Tiles}
  93.  SetBackgroundScrollRange(0,0,XMAX,YMAX);  {Tiles}
  94.  MakeTileArea(FirstTile,Tiles_per_Row,Tiles_per_Column);
  95.  
  96.  SetSplitIndex(Mouse + MaxFrame);
  97.  SetCycleTime(30);                       {millisec between frames}
  98.  SpriteN[Surf]:=LoadNumber;
  99.  SpriteN[Mouse]:=MouseHandle;            {clone sprite for default mouse}
  100.  
  101.  FrameCount := 1;                        {min frame number}
  102.  repeat
  103.  FOR x:=0 TO XMAX DO                     {vary the horizontal}
  104.   BEGIN
  105.    SpriteX[Surf]:=x;                     {sinusoid}
  106.    SpriteY[Surf]:=TRUNC( sin(2.0*pi*x/XMAX)*(YMAX SHR 1)+YMAX SHR 1 );
  107.  
  108.    Event.What := evNothing;              {ClearEvent}
  109.    GetMouseEvent(Event); {Drivers}
  110.    if (Event.What and evMouse) <> 0 then
  111.      if (Event.What = evMouseAuto) then
  112.      begin   {animate mouse when button held down.  Note: sporadic reporting}
  113.         SpriteN[Cartoon]:= OFF;
  114.         SpriteN[Mouse]:= OFF;
  115.         if (FrameCount < MaxFrame) then  {min..max frame or restart}
  116.           inc(FrameCount)  {min frame number}
  117.         else
  118.           FrameCount := 1;               {start}
  119.         SpriteN[Cartoon]:= FrameCount;
  120.         SpriteX[FrameCount]:= Event.Where.X shl 3;
  121.         SpriteY[FrameCount]:= Event.Where.Y shl 3;
  122.      end
  123.      else
  124.      begin   {default mouse cursor}
  125.         SpriteN[Cartoon]:= OFF;
  126.         SpriteN[Mouse]:= MouseHandle;
  127.         SpriteX[Mouse]:= Event.Where.X shl 3;
  128.         SpriteY[Mouse]:= Event.Where.Y shl 3;
  129.      end; {if}
  130.    {if "mouse (X,Y) within ClipRectangle" then}
  131.    UpdateOuterArea := 2;                 {Required for non-dynamic background}
  132.    Animate;
  133.   END;
  134.  
  135.   GetKeyEvent(Event);    {Drivers}
  136.  until (Event.What = evKeyDown);         {keypressed}
  137.  
  138.  CloseRoutines;
  139.  DoneEvents;             {Drivers}
  140. END.
  141.